<!--
 * @Author: your name
 * @Date: 2022-03-29 13:56:08
 * @LastEditTime: 2022-03-29 15:42:44
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \geyao\geyao\constructor220329.html
-->
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>constructor</title>
</head>
<body>
  <script>
    //属性的值是对函数本身的引用

    function father(name){
      this.name = name;
    }
    var gg=new father("father")
    console.log(gg.constructor,"gg")

    //ƒ father(name){
    //  this.name = name;
   // } 'gg'
  //创建自身属性的方法
   function Parent() {};
    function CreatedConstructor() {}

    CreatedConstructor.prototype = Object.create(Parent.prototype);
    //创建一个Parent的对象
    console.log( Object.create(Parent.prototype),"Parent")
    CreatedConstructor.prototype.constructor = CreatedConstructor; // 改变指向到父级
    CreatedConstructor.prototype.create = function create() {
      return new this.constructor();
    }

    new CreatedConstructor().create().create(); 
    //按照父亲级别的属性进行创造
    console.log(new CreatedConstructor().create().create(),"CreatedConstructor")
  </script>
</body>
</html>